﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using NHibernate;

namespace Cloak.Work.NHibernate
{
	/// <summary>
	/// A context in which work is committed outside of a transaction
	/// </summary>
	public sealed class NonAtomicWorkContext : IWorkContext
	{
		private readonly ISession _session;

		/// <summary>
		/// Initializes a context with the specified NHibernate session
		/// </summary>
		/// <param name="session">The session which tracks changes to the persistent state in this context</param>
		public NonAtomicWorkContext(ISession session)
		{
			Contract.Requires(session != null);

			_session = session;
		}

		/// <summary>
		/// Commits the changes which have occurred in this context
		/// </summary>
		public void Commit()
		{
			_session.Flush();
		}
	}
}